build: add optional hardened production flags#1138
Conversation
Signed-off-by: Pedro Ramos <131530838+pr9000@users.noreply.github.com>
|
Hi @DeusData, It looks like this PR is currently blocked by the From the workflow logs, the gate waits for the separate CodeQL workflow to complete, but the CodeQL run remained All other checks completed successfully. Would you mind re-running the CodeQL workflow (or the failed checks) for this PR? Thank you! |
|
Thanks for flagging the earlier timeout. The CodeQL workflow recovered without intervention and every check on exact head For the build direction, we do want production hardening, but not as a permanent FreeBSD-specific opt-in that leaves the standard release artifacts unchanged. Please rework this into a generic production-hardening policy: use platform/compiler capability rather than a FreeBSD name, enable the supported stack-protector, FORTIFY, RELRO, and immediate-binding protections by default for compatible ELF production builds, retain an explicit escape hatch for incompatible downstream toolchains, and leave sanitizer/test builds unchanged. The verification should inspect the produced standard artifacts for a non-executable stack, RELRO, and BIND_NOW where applicable. Keep this PR limited to that build policy; no unrelated build-system changes. |
|
Thanks for the detailed feedback. I'm glad to hear the goal of enabling production hardening aligns with the project's direction. My original Reworking this into a generic
Once I understand the intended scope, I'll rework the Makefile accordingly and keep this PR focused on the production hardening policy. |
What does this PR do?
Add an optional, non-intrusive production hardening option in
Makefile.cbm.This change was prepared alongside PR #1093 (
fix(foundation): use HW_PHYSMEM for physical memory detection on FreeBSD), but was split into a separate PR to keep the scope focused.The new
FREEBSD_HARDENINGoption supports hardened downstream packaging environments (for example, FreeBSD Ports Collection).Details
When enabled via
FREEBSD_HARDENING=1, production builds (cbmandcbm-with-ui) receive:-fstack-protector-strong-D_FORTIFY_SOURCE=2-Wl,-z,relro -Wl,-z,nowThe implementation keeps upstream impact minimal:
0), so existing builds, CI pipelines, and developer workflows are unchanged.CFLAGS_PROD,CXXFLAGS_PROD, andLDFLAGS.HARDEN_CFLAGSandHARDEN_LDFLAGSvariables to keep the build logic portable.Verified this locally on FreeBSD 15.1:
The resulting ELF binary was verified with:
Output:
and:
Output:
Both production targets were verified successfully with the hardening option enabled.
Checklist
git commit -s) — required, CI rejectsunsigned commits (DCO, see CONTRIBUTING.md)
make -f Makefile.cbm test)make -f Makefile.cbm lint-ci)